<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Vue-Learning</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.6/dist/vue.js"></script>

</head>

<body>

  <!-- 如果在root的div标签中加入v-text属性，div中内容会被覆盖 -->
  <div id="root">
    <!-- <h1 v-text="number"></h1> -->
    <div v-html="content" @click="parseContent"></div>
  </div>
  <script>
    new Vue({
      el: "#root",
      data: {
        number: "123",
        content: "<h3>hello</h3>"
      },
      methods: {
        parseContent: function() {
          this.content="<h3>world</h3>"
        }
      }
    })
  </script>
  <br>

  <!-- Vue中的属性单向绑定和双向数据绑定-->
  <div id="root2">
    <div v-bind:title="title">hello world</div>
    <div :title="title">hello world</div>
    <!-- 单向绑定，数据决定页面的显示，但页面不能改变数据的内容 -->
    <div>{{ name }}</div>

    <!-- 双向绑定,使用v-model，当页面变化时，数据也会变化 -->
    <input v-model="name" >
  </div>

  <script>
    new Vue({
      el: "#root2",
      data: {
        title: "this is hello world",
        name: "xiaoqiang"
      }
    }) 
  </script>
  <br>

  <!-- 计算属性和监听器 -->
  <div id="root3">
    姓:<input type="text" v-model="lastName">
    名:<input type="text" v-model="firstName">
    <div>{{ fullName }}</div>
    <div>{{ count }}</div>
  </div>
  <script>
    new Vue({
      el: "#root3",
      data: {
        lastName: "",
        firstName: "",
        count: 0
      },
      computed: {
        fullName: function() {
          return this.lastName + this.firstName;
        }
      },
      watch: {
        // lastName: function() {
        //   this.count++;
        // },
        // firstName: function() {
        //   this.count++;
        // }
        fullName: function() {
          this.count++;
        }
      }
    })
  </script>
  <br>

  <!-- v-for -->
  <div id="root4">
    <ul>
      <li v-for="item in list">{{item}}</li>
    </ul>
    <ul>
      <li v-for="(item, index) in list" :key="index">{{item}}</li>
    </ul>
  </div>
  <script>
    new Vue({
      el: "#root4",
      data: {
        list: [1,2,3]
      }
    })
  </script>

</body>

</html>